import lxml.etree as le

with open('edu.html','r',encoding='utf‐8') as f:
    # 读取本地的edu.html
    html = f.read()
    # 把html转成XML对象
    html_x = le.HTML(html)
    # 得到6个div对象
    div_x_s = html_x.xpath('//div[@class="nav_com"]/ul/li/a/text()')
    # 构造数据储存对象
    data_s = []
    i = 0
    # 对6个包含1级分类和2级分类对象做遍历
    for div_x in div_x_s:
    #     # 得到1级分类
        # category1 = div_x.xpath('./ul/li/a/text()')[i]
        # i = i+1
    #     # # 得到这个1级分类下的所有2级分类
    #     # category2_s = div_x.xpath('./div/span/a/text()')
    #     # 添加数据到储存对象
        data_s.append(
            dict(
                div_x = div_x
                # category1 = category1,
                # category2_s=category2_s
            )
        )

    # 打印data_s
    for data in data_s:
        print(data.get('div_x'))
        # for category2 in data.get('category2_s'):
        #     print(' ', category2)